package appindex

import (
	"lao-a/controllers"
	"lao-a/models/activity"
	"net/http"
)

// WechatIndexController 应用
type WechatIndexController struct {
	controllers.BaseController
}

// Constructor 初始化 Controller
// @Title Constructor
// @Description 初始化 Controller, 系统自动调用
func (c *WechatIndexController) Constructor() {
}

// Index 首页
func (c *WechatIndexController) Index() {

	// 活动相关
	act := activity.NewDAO(c.Context)

	activityTypes, e1 := act.GetActivityTypes()
	if e1 != nil {
		c.ResponseJson(e1, http.StatusInternalServerError)
	}

	activities, e2 := act.GetLimitActivitiesPerType(5)
	if e2 != nil {
		c.ResponseJson(e2, http.StatusInternalServerError)
	}

	actsInSlider, e3 := act.GetActivitiesInSlider(3)
	if e3 != nil {
		c.ResponseJson(e3, http.StatusInternalServerError)
	}

	c.ResponseJson(map[string]interface{}{
		"SliderItems":   actsInSlider,
		"ActivityTypes": activityTypes,
		"Activities":    activities,
	})
}
